package WarTug;

public class GardenButtons {

	private DrawableImage[][] images = new DrawableImage[Garden.GARDEN_HEIGHT][Garden.GARDEN_WIDTH];
	private DrawableImage[][] groundImages = new DrawableImage[Garden.GARDEN_HEIGHT][Garden.GARDEN_WIDTH];
	private DrawableImage selectedImage;
	private Garden garden;
	private GraphicsManager gMan;
	
	
	public GardenButtons(Garden garden, GraphicsManager g){
		this.garden = garden;
		gMan = g;
		int gX = garden.GARDEN_SCREEN_X;
		int gY = garden.GARDEN_SCREEN_Y;
		for (int i = 0; i < Garden.GARDEN_HEIGHT; i++){
			for (int j = 0; j < Garden.GARDEN_WIDTH; j++){
				DrawableImage temp = new DrawableImage(gX + j*garden.GARDEN_SQUARE_WIDTH + garden.GARDEN_SQUARE_WIDTH/2, gY + i*garden.GARDEN_SQUARE_WIDTH + garden.GARDEN_SQUARE_WIDTH/2, 
						25, garden.GARDEN_SQUARE_WIDTH, garden.GARDEN_SQUARE_WIDTH, TextureHolder.grass);
				groundImages[i][j] = temp;
				gMan.addDrawableEntity(temp);
			}
		}
		for (int i = 0; i < Garden.GARDEN_HEIGHT; i++){
			for (int j = 0; j < Garden.GARDEN_WIDTH; j++){
				DrawableImage temp = new DrawableImage(gX + j*garden.GARDEN_SQUARE_WIDTH + garden.GARDEN_SQUARE_WIDTH/2, gY + i*garden.GARDEN_SQUARE_WIDTH+ garden.GARDEN_SQUARE_WIDTH/2, 
						24, garden.GARDEN_SQUARE_WIDTH, garden.GARDEN_SQUARE_WIDTH, null);
				images[i][j] = temp;
				gMan.addDrawableEntity(temp);
			}
		}
		selectedImage = new DrawableImage(gX + garden.getSelectedSpace()[1]*garden.GARDEN_SQUARE_WIDTH+ garden.GARDEN_SQUARE_WIDTH/2, gY + garden.getSelectedSpace()[0]*garden.GARDEN_SQUARE_WIDTH+ garden.GARDEN_SQUARE_WIDTH/2, 
				23, garden.GARDEN_SQUARE_WIDTH, garden.GARDEN_SQUARE_WIDTH, TextureHolder.tileSelect);
		gMan.addDrawableEntity(selectedImage);
		refreshImages();
		
	}
	
	public void updateGarden(Garden g){
		garden = g;
		refreshImages();
	}
	
	public void refreshImages(){
		selectedImage.setX(garden.GARDEN_SCREEN_X + garden.getSelectedSpace()[1]*garden.GARDEN_SQUARE_WIDTH+ garden.GARDEN_SQUARE_WIDTH/2);
		selectedImage.setY(garden.GARDEN_SCREEN_Y + garden.getSelectedSpace()[0]*garden.GARDEN_SQUARE_WIDTH+ garden.GARDEN_SQUARE_WIDTH/2);
		for (int i = 0; i < Garden.GARDEN_HEIGHT; i++){
			for (int j = 0; j < Garden.GARDEN_WIDTH; j++){
				switch (garden.getSpaces()[j][i]) {
				case lion:
					groundImages[j][i].setTexture(TextureHolder.dirt);
					images[j][i].setTexture(TextureHolder.lion);
					break;
				case gazelle:
					groundImages[j][i].setTexture(TextureHolder.dirt);
					images[j][i].setTexture(TextureHolder.gazelle);
					break;
				case elephant:
					groundImages[j][i].setTexture(TextureHolder.dirt);
					images[j][i].setTexture(TextureHolder.elephant);
					break;
				case ostrich:
					groundImages[j][i].setTexture(TextureHolder.dirt);
					images[j][i].setTexture(TextureHolder.ostrich);
					break;
				default:
					break;
				}	
			}
		}
	}
	
}
